import { Component, Input, OnInit } from '@angular/core';
import { MyModalHelper } from '@core/my-modal.helper';
import { NzMessageService } from 'ng-zorro-antd';
import { CenterService } from '@core/routes-services/center.service';

@Component({
  selector: 'app-otc-salesman',
  templateUrl: './otc-salesman.component.html',
})
export class OtcSalesmanComponent implements OnInit {

  @Input() centerId:any;
  isLoading = false;
  keyword: any;
  page: any = { number: 1, size: 10, totalElements: 0, content: [] };
  sortMap = {
    totalCredit: null,
    residualCredit: null,
    totalTakCredit: null,
    residualTakCredit: null,
    saveTime: null,
    shopNum: 'descend',
  };
  sortName = null;
  sortValue = null;

  constructor(private message: NzMessageService,
              private centerService: CenterService,
              private modalHelper: MyModalHelper) {
  }

  ngOnInit() {
    this.initPage();
  }
  sort(sortName: string, value: string): void {
    this.sortName = sortName;
    this.sortValue = value ? value : 'ascend';
    for (const key in this.sortMap) {
      this.sortMap[key] = null;
      this.sortMap[key] = (key === sortName ? this.sortValue : null);
    }
    this.search();
  }
  initPage() {
    this.isLoading = true;
    this.centerService.salesmanPagination(this.page, this.keyword, this.centerId,  this.sortName, this.sortValue).then((res) => {
      if (res.status.toString().startsWith("20")) {
        this.page = res.data;
        ++this.page.number;
      } else {
        this.message.warning(res.message);
      }
      this.isLoading = false;
    }, error => {
      this.message.error(error.message ? error.message : error.error)
      this.isLoading = false;
    });
  }

  /**
   * 搜索重置分页数据
   */
  search() {
    this.page = { number: 0, size: 10, totalElements: 0, content: [] };
    this.initPage();
  }

  changePageNo(pageNo) {
    this.page = { number: pageNo, size: 10, totalElements: 0, content: [] };
    this.initPage();
  }




}
